home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Blender 2.49b / blender-2.49b-windows.exe / $_4_ / .blender / scripts / bpymodules / BPyCurve.py < prev    next >
Text File  |  2009-08-31  |  2KB  |  80 lines

  1. # --------------------------------------------------------------------------
  2. # BPyImage.py version 0.15
  3. # --------------------------------------------------------------------------
  4. # helper functions to be used by other scripts
  5. # --------------------------------------------------------------------------
  6. # ***** BEGIN GPL LICENSE BLOCK *****
  7. #
  8. # This program is free software; you can redistribute it and/or
  9. # modify it under the terms of the GNU General Public License
  10. # as published by the Free Software Foundation; either version 2
  11. # of the License, or (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with this program; if not, write to the Free Software Foundation,
  20. # Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  21. #
  22. # ***** END GPL LICENCE BLOCK *****
  23. # --------------------------------------------------------------------------
  24.  
  25. from Blender import *
  26.  
  27. def curve2vecs(ob, WORLDSPACE= True):
  28.     '''
  29.     Takes a curve object and retuirns a list of vec lists (polylines)
  30.     one list per curve
  31.     
  32.     This is usefull as a way to get a polyline per curve
  33.     so as not to have to deal with the spline types directly
  34.     '''
  35.     if ob.type != 'Curve':
  36.         raise 'must be a curve object'
  37.     
  38.     me_dummy = Mesh.New()
  39.     me_dummy.getFromObject(ob)
  40.     
  41.     if WORLDSPACE:
  42.         me_dummy.transform(ob.matrixWorld)
  43.     
  44.     # build an edge dict
  45.     edges = {} # should be a set
  46.     
  47.     def sort_pair(i1, i2):
  48.         if i1 > i2:        return i2, i1
  49.         else:            return i1, i2
  50.     
  51.     for ed in me_dummy.edges:
  52.         edges[sort_pair(ed.v1.index,ed.v2.index)] = None # dummy value
  53.     
  54.     # now set the curves
  55.     first_time = True
  56.     
  57.     current_vecs = []
  58.     vec_list = [current_vecs]
  59.     
  60.     for v in me_dummy.verts:
  61.         if first_time:
  62.             first_time = False
  63.             current_vecs.append(v.co.copy())
  64.             last_index = v.index
  65.         else:
  66.             index = v.index
  67.             if edges.has_key(sort_pair(index, last_index)):
  68.                 current_vecs.append( v.co.copy() )
  69.             else:
  70.                 current_vecs = []
  71.                 vec_list.append(current_vecs)
  72.             
  73.             last_index = index
  74.     
  75.     me_dummy.verts = None
  76.     
  77.     return vec_list
  78.     
  79.  
  80.